home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
comm
/
misc
/
mirrorman_1_10b1.lha
/
MirrorManager-1.10b1
/
rexx
/
Demo.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-06-24
|
21KB
|
671 lines
/*rx
**
** $VER: $Id: Demo.rexx,v 1.9 1994/06/24 16:46:44 tf Exp $
**
** This is a tutorial .rexx script demonstrating the powerful ARexx port
** of the MirrorManager GUI. It is executable via RX and runs it's own
** MirrorManager host if needed.
**
** MirrorManager is (C) Copyright 1994 by Harald Kunze and Tobias Ferber
**
** Initial revision (hacked in a hurry) by Tobias Ferber, 27-Feb-94
*/
appstart = 'Run /MirrorManager'
portbase = 'MIRRORMANAGER.'
def_stacksize = 10240
portlist = ""
options results
myname = whoami()
args = ""
label = "" /* name of the procedure to be CALLed */
signal on HALT
signal on BREAK_C
signal on BREAK_D
call pragma('W','N')
if ~exists(myname) then do
if abbrev(address(),portbase) then do
REQUESTCHOICE TITLE '"MirrorManager"',
BODY '"This tutorial script is nested deply*n' ||,
'in your directory hierarchy...*n' ||,
'I''ve been unable to locate myself"',
GADGETS '"Exit"'
end
else if exists('c:requestchoice') then do
address command 'c:requestchoice >nil:',
'TITLE "MirrorManager"',
'BODY "This tutorial script seems to be nested deeply*n' ||,
'in your directory hierarchy...*n' ||,
'I''ve been unable to locate myself..."',
'GADGETS "Exit"'
end
else say 'MirrorManager is located too deep in your directory hierarchy...'
exit 10
end
/* BEGIN BUGGY CALLING METHOD
if pos(' ',myname) > 0 then do
if abbrev(address(),portbase) then do
REQUESTCHOICE TITLE '"MirrorManager WARNING"',
BODY '"The pathname of this tutorial script*n' ||,
'contains a space character...*n' ||,
'This might be a problem for ARexx !"',
GADGETS '"We''ll see"'
end
else if exists('c:requestchoice') then do
address command 'c:requestchoice >nil:',
'TITLE "MirrorManager WARNING"',
'BODY "The pathname of this tutorial script*n' ||,
'contains a space character...*n' ||,
'This might be a problem for ARexx !"',
'GADGETS "We''ll see"'
end
else do
say 'The pathname of this tutorial script contains a space character...'
say 'This might be a problem for ARexx !'
end
end
END BUGGY CALLING METHOD */
if arg() > 0 then do
portname= arg(1)
if abbrev(portname,portbase) then do
address(portname)
if arg() > 1 then do
label = upper( arg(2) )
do ac= 3 while ac <= arg()
args= args || '0a'x || arg(ac)
end
end
end
else do
say 'Usage:' myname '[ MIRRORMANAGER.<x> ] [label]'
exit
end
end
else do
if ~abbrev(address(),portbase) then do
/***
if exists('c:requestchoice') then do
address command 'c:requestchoice >nil:',
'TITLE "MirrorManager"',
'BODY "This is a tutorial demo script.*n' ||,
'Please double-click the Configure icon*n' ||,
'in your MirrorManager/rexx drawer to*n' ||,
'setup MirrorManager for your system."',
'GADGETS "Okay"'
end
***/
portlist = SHOW('P',,'0A'X)
do while words(portlist) > 0
parse var portlist portname '0A'X portlist
if abbrev(portname,portbase) then do
address(portname); 'NUMENTRIES'
if result = 0 then portlist= ""
else address
end
end
if address() ~= portname then do
stacksize= pragma('S',def_stacksize)
address command appstart 'CONFIGNAME='transquote(myname)
call pragma('S',stacksize)
exit
end
end
else do
portname= address()
REQUESTCHOICE TITLE '"MirrorManager"',
BODY '"This is a tutorial demo script.*n' ||,
'Please double-click the Configure icon*n' ||,
'in your MirrorManager/rexx/ drawer to*n' ||,
'setup MirrorManager for your system."',
GADGETS '"Okay"'
end
end
CONFIGNAME transquote(myname)
signal on ERROR
signal on IOERR
signal on FAILURE
/*signal on NOVALUE*/
signal on SYNTAX
/* list of legal procedures */
proctab= 'WELCOME:SCRIPTINFO:DRIVING:HAESSLICH:SHOWHELP:MOVEME:MMREQ:LOADCONFIG:APPINFO:'
IF (WORDS(label) > 0) THEN DO
IF (POS(label':',proctab) > 0) THEN INTERPRET 'CALL' label
ELSE DO
ESC= '1b'x
REQUESTCHOICE TITLE '"Tutorial Demo"',
BODY '"Unrecognized keyword:*n*n'ESC'c'ESC'b'label || ESC'n'ESC'l"',
GADGETS '"Hmmm..."'
CALL WELCOME
END
END
ELSE CALL WELCOME
EXIT
WELCOME: procedure expose portname myname
clear; configname transquote(myname)
'MESSAGE CLOSE'
call scroll_item ('Welcome to MirrorManager')
call add_item ('... your local Aminet mirror management system')
call add_item ('')
call add_item ('Please select one of the following items:')
call add_item ('')
add '"» Show HELP on ARexx commands"' transquote(myname) '"' || portname 'SHOWHELP' || '"'
add '"» Display application INFO"' transquote(myname) '"' || portname 'APPINFO' || '"'
add '"» Get info on script files"' transquote(myname) '"' || portname 'SCRIPTINFO' || '"'
add '"» Add a moving item"' transquote(myname) '"' || portname 'MOVEME' || '"'
add '"» Add a jumping item"' transquote(myname) '"' || portname 'MOVEME' || '"'
add '"» Go for a drive..."' transquote(myname) '"' || portname 'DRIVING' || '"'
add '"» Show fix-width font banner"' transquote(myname) '"' || portname 'HAESSLICH' || '"'
add '"» Have a MUI requester"' transquote(myname) '"' || portname 'MMREQ' || '"'
add '"» Load another configuration"' transquote(myname) '"' || portname 'LOADCONFIG' || '"'
configname; cname= result
add '"» Restart this demo script"' transquote(cname) portname
return 0
SCRIPTINFO: procedure expose portname myname args
ESC = '1B'x
if words(args) > 0 then do
parse var args '0a'x fname '0a'x fnote
parse var fname . '.' suffix
if (upper(suffix) = 'REXX') | (upper(suffix) = 'MM') then call MSGCOMMENT('rexx/'fname)
if words(fnote) > 0 then
requestchoice title '"Information on ' || fname || '"',
body '"' || ESC'b' || fname || ESC'n' || ' has the following filenote:*n' ||,
ESC'c' || fnote || ESC'l"',
gadgets '"Thank you"'
else
requestchoice title '"Information on ' || fname || '"',
body '"' || ESC'b' || fname || ESC'n' || ' has no filenote."',
gadgets '"Sorry"'
end
else do
clear; configname transquote(myname)
message clear; message open
tempfile= 't:items.' || pragma('Id')
working '"Generating list of available script files..."'
complete 10
address command 'list > "' || tempfile || '" files dir rexx lformat "%n;%c"'
complete 20
if ~open('fp',tempfile,'r') then do
message '"Failed to create temprary file ' || tempfile || '"'
exit
end
working '"Reading script file information..."'
c= 30
do until eof('fp')
if c < 90 then do; complete c; c= c+2; end
str= strip( readln('fp') )
if words(str) > 0 then do
parse var str fname ';' fnote
if words(fnote) > 0 then
add '"' || fname || '"' transquote(myname) '"' || portname 'SCRIPTINFO *"'fname'*" *"'fnote'*""'
else
add '"' || fname || ' (no filenote)"' transquote(myname) '"' || portname 'SCRIPTINFO *"'fname'*""'
end
end
call close('fp')
complete 90
working '"Deleting temporary file..."'
address command 'delete quiet file' tempfile
working '"Sorting MirrorManager ListView..."'
complete 95
sort
add '"»»» Click here to return to MENU «««"' transquote(myname) '"' || portname 'WELCOME' || '"'
working '"done. Press the [HELP] key for more information..."'
complete 100
end
return 0
DRIVING: procedure expose portname myname
w=10; i=5; c=100; call time('r')
message clear; message open
working '"Driving...."'
do r=0 for 5 by 5
do n=0 for r
complete c; c=c-1
add_item(copies(' ',i+n) '|' copies(' ',w) '¦' copies(' ',w) '|')
end
do n=1 for r
complete c; c=c-1
add_item( copies(' ',i+r-n) '|' copies(' ',w) '¦' copies(' ',w) '|')
end
i= i+1
end
add '"»»» Click here to return to MENU «««"' transquote(myname) '"' || portname 'WELCOME' || '"'
working '"done."'
complete 0
requestchoice title '"Driving Statistics..."',
body '"This drive took' time('e') 'seconds"',
gadgets '"Okay"'
return 0
HAESSLICH: procedure expose portname myname
clear; configname transquote(myname) ;message clear; message open
call add_item ('This is')
call add_item ('')
call add_item (' MM MM ii ') ;message '" _ _ __ "'
call add_item (' MMM MMM ') ;message '" / \_/ \ /_/ "'
call add_item (' MMMMMMM ii rrrrr rrrrr oooo rrrrr ') ;message '" / \__/ /__ _____ _____ ______ _____"'
call add_item (' MM M MM ii rr rr rr rr oo oo rr rr') ;message '" / / / // / / .__// .__// __ // .__/"'
call add_item (' MM MM ii rr rr oo oo rr ') ;message '" / / / // /_ / / / / / /_/ // / "'
call add_item (' MM MM ii rr rr oo oo rr ') ;message '" /_/ /_//___//_/ /_/ /_____//_/ "'
call add_item (' MM MM ii rr rr oooo rr ')
call add_item ('')
call add_item ('MM MM ') ;message '" _ _ "'
call add_item ('MMM MMM ') ;message '" / \_/ \ "'
call add_item ('MMMMMMM aaaa nnnnn aaaa ggggg eeee rrrrr ') ;message '" / \__/ /______ ______ ______ ______ ______ _____"'
call add_item ('MM M MM aa nn nn aa gg gg ee ee rr rr') ;message '" / / / // __ // __ // __ / / __ // ____// .__/"'
call add_item ('MM MM aaaaa nn nn aaaaa gg gg eeeeee rr ') ;message '" / / / // __ // / / // __ / / /_/ // __/_ / / "'
call add_item ('MM MM aa aa nn nn aa aa ggggg ee rr ') ;message '"/_/ /_//_/ /_//_/ /_//_/ /_/ _\__ //_____//_/ "'
call add_item ('MM MM aaaaa nn nn aaaaa gg eeee rr ') ;message '" /_____/ "'
call add_item (' gggg ') ;message '" "'
call add_item ('') ;message '" ...YOUR Aminet mirror management system "'
call scroll_item(' ...YOUR Aminet mirror management system')
call add_item ('')
add '"»»» Click here to return to MENU «««"' transquote(myname) '"' || portname 'WELCOME' || '"'
return 0
SHOWHELP: procedure expose portname myname
helpfile= 't:help'
working '"Generating help file... Please wait..."'
help helpfile
if ~open('fp',helpfile,'r') then do
working '"HELP failed to create' helpfile '!"'
exit
end
message clear; message open
do l=0 until eof('fp')
complete min(3*l,100)
message '"'translate(strip(readln('fp')),"'",'"')'"'
working '"reading line' l'"'
end
call close('fp')
working '"deleting temporary help file..."'
address command 'delete quiet file' helpfile
complete 100
working '"done. Press the [HELP] key for more information..."'
return 0
/*
* Load a new configuration
*/
LOADCONFIG: procedure expose portname myname
ESC = '1B'x
cwd= strip(pragma('D'),'B','"')
SIGNAL OFF ERROR
REQUESTFILE DRAWER '"'cwd'"' TITLE '"Select a config file..."' NOICONS
SIGNAL ON ERROR
if (result ~= 'RESULT') then do
fname = result
if exists(fname) then do
parse var fname . '.' suffix
if (upper(suffix) = 'REXX') | (upper(suffix) = 'MM') then do
p= MAX( lastpos(':',fname), lastpos('/',fname) )
if p > 0 then f= substr(fname,p+1)
else f= fname
call MSGCOMMENT(fname)
REQUESTCHOICE TITLE '"Tutorial Demo"',
BODY '"You are about to leave this tutorial demo for*n*n' ||,
ESC'c'ESC'b' || f || ESC'n'ESC'l*n*n' ||,
'Everything you worked on so hard will be lost !*n' ||,
'Are you really sure that you can afford that risk ?"',
GADGETS '"Yes"'
CLEAR
LOCK OFF
LOAD transquote(fname)
exit
end
else do
REQUESTCHOICE TITLE '"Tutorial Demo -- Bad suffix' suffix'"',
BODY '"I''m afraid I will not execute any configuration script*n' ||,
'with a suffix other than either' ESC'b.rexx'ESC'n or' ESC'b.mm'ESC'n*n' ||,
'from within this tutorial demo!"',
GADGETS '"Forget about it"'
end
end
else do
REQUESTCHOICE TITLE '"Tutorial Demo"',
BODY '"Selected config script does not exist:*n' ||,
ESC'c'ESC'b' || fname || ESC'n'ESC'l' || '"',
GADGETS '"Resume"'
end
end
return 0
/*
* handle moving items
*/
MOVEME: procedure expose portname myname
activate; select
when word(result,4) = 'moving' then add '"« move-up »"' transquote(myname) '"'portname 'MOVEME"'
when word(result,4) = 'jumping' then add '"« jump-top »"' transquote(myname) '"'portname 'MOVEME"'
when result = '« move-up »' then do;
up
if result < 1 then rename '"« move-down »"'
end
when result = '« move-down »' then do
numentries; last= result
down
if result >= last-1 then rename '"« move-up »"'
end
when result = '« jump-top »' then do; top; rename '"« jump-bottom »"'; end
when result = '« jump-bottom »' then do; bottom; rename '"« jump-top »"'; end
otherwise rename '"??? Did you rename me ???"'
end
return 0
/*
* Demonstrate MUI's text engine
*/
MMREQ: procedure
ESC = '1b'x
NL = '*n'
RequestChoice TITLE '"MirrorManager Request"',
BODY '"' ||,
'... using MUI''s powerful text engine' || NL ||,
ESC'c' || NL ||,
ESC'u' || 'underlined' || ESC'n' || NL ||,
ESC'b' || 'bold' || ESC'n' || NL ||,
ESC'i' || 'italic' || ESC'n' || NL ||,
NL ||,
ESC'r' || 'right justified' || NL ||,
ESC'l' || 'left justified' ||,
'"',
GADGETS '"'date('w')'|'date('n')'|'time('n')'"'
/*
ESC'I' || '3:mui-xenknob.image' || NL ||,
ESC'I' || '5:xtras/MirrorManager.brush' ||,
*/
return 0
/*
* Show application information
*/
APPINFO: procedure
ESC = '1b'x
NL = '*n'
MESSAGE CLEAR; MESSAGE OPEN; WORKING '"Reading Application information ..."'
COMPLETE 0; 'INFO Title'; MESSAGE transquote("Title......: " result) /* Application title */
COMPLETE 15; 'INFO Author'; MESSAGE transquote("Author.....: " result) /* Author of the applic */
COMPLETE 30; 'INFO Copyright'; MESSAGE transquote("Copyright..: " result) /* Copyright message */
COMPLETE 45; 'INFO Description'; MESSAGE transquote("Description: " result) /* Short description */
COMPLETE 60; 'INFO Version'; MESSAGE transquote("Version....: " result) /* Version string */
COMPLETE 75; 'INFO Base'; MESSAGE transquote("Basename...: " result) /* Name of the ARexx port */
COMPLETE 90; 'INFO Screen'; MESSAGE transquote("Screen.....: " result) /* Name of the pub screen */
COMPLETE 100; WORKING '"Application information"'
return 0
/*
* This procedure prints the first ARexx comment in the given file to the
* Message window. Nested comments ARE supported.
*/
MSGCOMMENT: procedure
parse arg fname
if open('fp',fname,'R') then do
n= 0;
MESSAGE CLEAR; MESSAGE OPEN
WORKING '"'fname'"'
do while (n=0) & ~eof('fp')
line= readln('fp')
n= count('/*',line)
end
do while (n>0) & ~eof('fp')
MESSAGE transquote(line)
n= n - count('*/',line)
if n>0 then do
line= readln('fp')
n= n + count('/*',line)
end
end
call close('fp')
end
return 0
/*
** FUNCTIONS OF GENERAL USE
*/
/* translate '"' into '*"' and '*' into '**' */
transquote: procedure
parse arg s
t= s
q= max( lastpos('*',s), lastpos('"',s) )
do while q > 0
t= insert('*',t,q-1,1)
s= left(s,q-1)
q= max( lastpos('*',s), lastpos('"',s) )
end
return '"' || t || '"'
/* counts the occurences of t in s */
count: procedure
parse arg t,s
n=0; p=0;
do while p>=0
p= pos(t,s,p+1)
if p>0 then n=n+1
else p=p-1
end
return n;
/* add an item -- character by character */
scroll_item: procedure expose portname
parse arg str
call add_item(' ')
do l=1 for length(str)
RENAME '"' || right(str,l) || '"'
call wait .1
end
return 0
/* add a no-op item */
add_item: procedure expose portname
parse arg s
t= ""
q= pos('"',s)
if q > 0 then do while q > 0
t= t || left(s,q-1) || '*"'
s= delstr(s,1,q)
q= pos('"',s)
end
add '"' || t || s || '"' '"*"address ''' || portname || ''' requestchoice',
'title ''*"*"Information...*"*"''',
'body ''*"*"Clicking this item is a'' ''1B''x''bno-op''||''1B''x''n !*"*"''',
'gadgets ''*"*"Hmmm...*"*"''"'
return 0
/* celibrate a delay loop */
wait: procedure
arg delay
call time('r')
do while(time('e') < delay)
nop
end
return 0
/* resolve the scriptfile name of THIS .rexx script */
whoami: procedure
parse source . . s
t= left(s,lastpos(':',s))
called= strip( left(t,lastpos(' ',t)) )
call pragma('W','N')
do while ~exists(called) & lastpos(' ',called) > 0
called= left(called,lastpos(' ',called)-1)
end
host= address()
parse var s (called) s (host) .
resolved= strip(s)
call pragma('W','N')
do while ~exists(resolved)
resolved= left(resolved,lastpos(' ',resolved)-1)
end
return resolved
/* error/break handling */
IOERR:
ERROR:
err= rc
ESC = '1b'x
signal off ERROR
signal off IOERR
WORKING '"I/O problem trapped... Execution halted."'
MESSAGE '"I/O problem trapped... Execution halted."'
REQUESTCHOICE TITLE '"Tutorial Error Trap' err'"',
BODY '"There was a problem with external I/O in line' sigl '...*n' ||,
ESC'c'ESC'b' || ERRORTEXT(err) || ESC'n'ESC'l' || '"',
GADGETS '"I''ll better exit"'
EXIT 0
FAILURE:
NOVALUE:
SYNTAX:
err= rc
ESC = '1b'x
signal off FAILURE
signal off NOVALUE
signal off SYNTAX
WORKING '"Internal problem trapped... Execution halted."'
MESSAGE '"Internal problem trapped... Execution halted."'
REQUESTCHOICE TITLE '"Tutorial Internal Error' err'"',
BODY '"We seem to have an internal problem in line' sigl '...*n' ||,
ESC'c'ESC'b' || ERRORTEXT(err) || ESC'n'ESC'l' || '"',
GADGETS '"I''ll better exit"'
EXIT 0
HALT:
BREAK_C:
BREAK_D:
signal off HALT
signal off BREAK_C
signal off BREAK_D
WORKING '"Break signal trapped... Execution halted."'
MESSAGE '"Break signal trapped... Execution halted."'
REQUESTCHOICE TITLE '"Tutorial Break Trap"',
BODY '"Script execution halted."',
GADGETS '"Stop"'
EXIT 0
/* END */